<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>yaml编辑</title>
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
		<link
			rel="stylesheet"
			data-name="vs/editor/editor.main"
			href="/monaco-editor/min/vs/editor/editor.main.css"
		/>
    <script src="/js/jquery.min.js"></script>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div id="container" style="width: 100%; height:450px; border: 1px solid grey"></div>
        <br>
        <fieldset class="table-search-fieldset">
            <legend></legend>
            <button class="layui-btn layui-btn-sm" id="SaveBtn" >创建deployment</button>
            <a href="https://k8syaml.com/"  target="_blank" class="layui-btn layui-btn-normal layui-btn-sm">yaml语法在线编写</a>
        </fieldset>   
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
	var require = { paths: { vs: '/monaco-editor/min/vs' } };
</script>
<script src="/monaco-editor/min/vs/loader.js"></script>
<script src="/monaco-editor/min/vs/editor/editor.main.nls.js"></script>
<script src="/monaco-editor/min/vs/editor/editor.main.js"></script>
<script>

SetDefaultCluster();
var clusterId = getQueryString("clusterId");
if (clusterId == null) {
	clusterId = getCookie("clusterId")
}

var Apiver = "v1";
var clusterIdVersion = getCookie(clusterId);
if ( compareVersions("1.20.1",clusterIdVersion) == 1 ) {
  Apiver = "v1beta1";
}

    layui.use(['form', 'table','code'], function () {
        var $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        
    		var editor = monaco.editor.create(document.getElementById('container'), {
    			value: '',
    			language: 'yaml',
    			//automaticLayout: true,
    			minimap: {enabled: false},
    			wordWrap: 'on',
    			theme: 'vs-dark'
    		});

			//monaco.editor.setTheme('vs-dark');
			//var code = `function x() {', '\tconsole.log("Hello world!");', '}`;			
			//console.log(editor.getValue());

        $('#SaveBtn').on("click",function(){
              layer.confirm('确定修改?', {icon: 3, title:'提示',yes: function(index){
                 $.ajax({
                   url: "/xkube/ingress/"+Apiver+"/CreateByYaml"+location.search,
                   type: "POST",
                   data: editor.getValue(),
                   dataType: "json",
                   success: function (resp) {
                      //resp = JSON.stringify(resp),
                      //console.log(resp);
                      //layer.close(index);
                      layer.msg(resp.msg);
                    }
                 });
                  //console.log(editor.getValue());
                  //layer.msg('ok');
              },
              cancel: function(index, layero){ 
                  layer.close(index);
              } 
            });
        });
    });
</script>

</body>
</html>